<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>登录页面</title>
<script type="text/javascript">
if(top.location!=self.location){
	parent.window.location=window.location.href;
}
</script>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="author" content="yinqi">
<link href="../static/css/bootstrap.min.css" rel="stylesheet">
<link href="../static/css/materialdesignicons.min.css" rel="stylesheet">
<link href="../static/css/style.min.css" rel="stylesheet">
<style>
.lyear-wrapper {
    position: relative;
}
.lyear-login {
    display: flex !important;
    min-height: 100vh;
    align-items: center !important;
    justify-content: center !important;
}
.lyear-login:after{
    content: '';
    min-height: inherit;
    font-size: 0;
}
.login-center {
    background-color: rgba(255,255,255,.075);
    min-width: 29.25rem;
    padding: 2.14286em 3.57143em;
    border-radius: 3px;
    margin: 2.85714em;
}
.login-header {
    margin-bottom: 1.5rem !important;
}
.login-center .has-feedback.feedback-left .form-control {
    padding-left: 38px;
    padding-right: 12px;
    background-color: rgba(255,255,255,.075);
    border-color: rgba(255,255,255,.075)
}
.login-center .has-feedback.feedback-left .form-control-feedback {
    left: 0;
    right: auto;
    width: 38px;
    height: 38px;
    line-height: 38px;
    z-index: 4;
    color: #dcdcdc;
}
.login-center .has-feedback.feedback-left.row .form-control-feedback {
    left: 15px;
}
.login-center .form-control::-webkit-input-placeholder{ 
    color: rgba(255, 255, 255, .8);
} 
.login-center .form-control:-moz-placeholder{ 
    color: rgba(255, 255, 255, .8);
} 
.login-center .form-control::-moz-placeholder{ 
    color: rgba(255, 255, 255, .8);
} 
.login-center .form-control:-ms-input-placeholder{ 
    color: rgba(255, 255, 255, .8);
} 
 .login-center .custom-control-label::before {
    background: rgba(0, 0, 0, 0.3);
    border-color: rgba(0, 0, 0, 0.1);
} 
 .login-center .lyear-checkbox span::before {
    border-color: rgba(255,255,255,.075)
} 
</style>
</head>
  
<body>
<div class="row lyear-wrapper" style="background-image: url(../static/img/login-bg-3.jpg); background-size: cover;">
  <div class="lyear-login">
    <div class="login-center">
      <div class="login-header text-center">
        <a href="#!"><h3>Xyan自适应管理系统</h3></a> 
      </div>
      <form  class="layui-form" action="" onsubmit="return false;">
            <input id="_method" type="hidden" name="_method" value="PUT">
        <div class="form-group has-feedback feedback-left">
          <input type="text" placeholder="请输入您的用户名" class="form-control" name="user_name" id="username" />
          <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
        </div>
        <div class="form-group has-feedback feedback-left">
          <input type="password" placeholder="请输入密码" class="form-control" id="password" name="password" />
          <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
        </div>
		
		<div class="form-group has-feedback feedback-left">
		  <div id="slider"></div>
		</div>
		
        <div class="form-group">
          <label class="lyear-checkbox checkbox-primary m-t-10 text-white">
            <input type="checkbox"><span>3天内自动登录</span>
          </label>
        </div>
        <div class="form-group">
          <button class="btn btn-block btn-primary" type="button" type="submit"  lay-submit lay-filter="formDemo">立即登录</button>
        </div>
      </form>
      <footer class="col-sm-12 text-center text-white">
        <p class="m-b-0"></p>
      </footer>
    </div>
  </div>
</div>
<script src="/admin/utils/layui/layui.js" charset="utf-8"></script>
<script src="/admin/utils/layui/config.js" charset="utf-8"></script>
<script>
	layui.use(['form', 'helper', 'sliderVerify'], function () {
		if(isMobileUserAgent()){
			layer.confirm('当前为移动设备访问,建议您使用横屏模式浏览。', {
			  btn: ['知道了'] //按钮
			}, function(){
				layer.closeAll();
			});
		}
		var form = layui.form;
		var sliderVerify = layui.sliderVerify;
		var notice = layui.notice; // 允许别名 toastr
		var slider = sliderVerify.render({
			elem: '#slider'
		})
		var $ = layui.$;
		//清空掉所有的cookie session
		sessionStorage.clear();
		localStorage.clear();
		var date=new Date();
		date.setTime(date.getTime()-10000);
		var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
		if (keys) {
			for (var i =  keys.length; i--;)
			  document.cookie=keys[i]+"=0; expire="+date.toGMTString()+"; path=/";
		}
		///////////
		  //监听提交
		form.on('submit(formDemo)', function(data){
			var fmdata =  data.field;
			if(slider.isOk()){//用于表单验证是否已经滑动成功
				var index = layer.load(1, {
					shade: [0.3, '#000'] //0.1透明度的白色背景
				});
				var request = $.ajax({
					url: baseApi.loginUrl,
					method: "POST",
					timeout: 10000,
					data: fmdata,
					dataType: 'json',
					// mimeType: "multipart/form-data",
					// processData: false,
					// contentType: false
				});
				
				request.done(function(res) {
					layer.close(index);
					
					if($_GET['referer']){
						var referer = window.atob($_GET['referer']);
						//ok 乱码后就无法出现?api
						if(referer && strrpos(referer, '?api') >= 0){
							return window.location = referer;
						}
					}
					
					window.location = '/admin';
				});
				
				request.fail(function(jqXHR) {
					layer.close(index);
					console.error(jqXHR);
					if (jqXHR.responseJSON && jqXHR.responseJSON.errormsg) {
						noticeMsg('error', jqXHR.responseJSON.errormsg);
					} else {
						if (jqXHR.responseText) {
							alert(jqXHR.responseText);
						} else {
							alert(jqXHR.statusText);
						}
					}
				});
			
			}else{
				noticeMsg('error',"请先通过滑块验证");
			}
		  
		  return false;
		});
		
	});
</script>
</body>
</html>